import { useEffect, useState } from 'react'
// import { useParams } from 'react-router-dom'
import { Category, Datum, ReqParams, fetchSupportListAPI } from '@/apis/supportProb'
// import { log } from 'console'

function useProblemList() {
  const [isLoading, setLoading] = useState<boolean>(false)
  // 标题
  const [headers, setHeaders] = useState<Category>()
  // 图片
  const [imgs, setImgs] = useState<Datum[]>([])
  // const params = useParams()
  // const id = params.id
  // console.log(id);
  const [params, ] = useState<ReqParams>({ page: "1", pageSize: "10"})
  useEffect(() => {
    const getProblemList = async () => {
      try {
        setLoading(true)
        const res = await fetchSupportListAPI(params)
        // console.log(res);
        setHeaders(res.data.category[0])
        setImgs(res.data.data)
        setLoading(false)
      } catch (error) {
        throw new Error('fetch ProblemList error')
      }
    }
    getProblemList()
  }, [])
  // 暴露数据
  return {
    headers, imgs, isLoading
  }
}

export { useProblemList }
